package com.minhua.jijiehao2.mainframe.launcher.finalregisteractivity.impl

import com.minhua.jijiehao2.base.BaseMvpPresenter
import com.minhua.jijiehao2.bean.BaseBean
import com.minhua.jijiehao2.bean.LoginBean
import com.minhua.jijiehao2.constants.DefineKey
import com.minhua.jijiehao2.http.CallBack
import com.minhua.jijiehao2.http.ParamsMap
import com.minhua.jijiehao2.mainframe.launcher.finalregisteractivity.imp.IFinalRegisterPresenter
import com.minhua.jijiehao2.mainframe.launcher.finalregisteractivity.imp.IFinalRegisterView
import com.minhua.jijiehao2.utils.InputUtils
import com.minhua.jijiehao2.utils.T
import com.minhua.jijiehao2.utils.encryption.MDUtil

class FinalRegisterPresenter : BaseMvpPresenter<IFinalRegisterView>(), IFinalRegisterPresenter {

    private val mFinalRegisterModel = FinalRegisterModel()

    override fun doRegister() {
        val phone = v?.getPhone() ?: ""
        val code = v?.getCode() ?: ""
        val password = v?.getPassword()
        if (!InputUtils.checkCellphone(password)) {
            T.showShort("密码由6-20位数字字母组成")
        }
        val map = ParamsMap()
        map.put(DefineKey.LOGIN_PHONE, phone)
        map.put(DefineKey.LOGIN_PASSWORD, MDUtil.encode(MDUtil.TYPE.MD5, password).toUpperCase())
        map.put(DefineKey.CHECK_CODE, code)
        map.put(DefineKey.CHANNEL_CODE, "guanfang")
        map.put(DefineKey.MOBILE_TYPE, DefineKey.MOBILE_TYPE_VALUE)
        mFinalRegisterModel.doRegister(map, object : CallBack<LoginBean>() {
            override fun onSuccess(t: BaseBean<LoginBean>) {
                t.data?.let { mFinalRegisterModel.saveLoginInfo(it) }
                v?.onRegisterSuccess()
            }
        })
    }
}